import java.io.*;
import java.nio.charset.StandardCharsets;
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        System.out.println(main.maxArea(new int[]{1, 8, 6, 2, 5, 4, 8, 3, 7}));
        main.moveZeroes(new int[]{0,1,0,3,12});
        System.out.println(Arrays.toString(main.sum(new int[]{2, 7, 11, 15}, 9)));
    }
    public int maxArea(int[] height) {
        int left = 0;
        int right = height.length - 1;
        int ans = 0;
        while(left < right){
            if (height[left] > height[right]) {
                ans = Math.max(ans, (right - left) * height[right]);
                right--;
            }
            else {
                ans = Math.max(ans, (right - left) * height[left]);
                left++;
            }
        }
        return ans;
    }
    public void moveZeroes(int[] nums) {
//        for (int i = 0; i < nums.length; i++) {
//            if (nums[i] != 0) continue;
//            for (int j = i; j < nums.length - 1; j++) {
//                int temp = nums[j];
//                nums[j] = nums[j+1];
//                nums[j+1] = temp;
//            }
//        }
        int zero = 0;
        int left = 0;
        int right = 0;
        while(right < nums.length){
            if (nums[right] == 0){
                zero++;
            }else {
                nums[left] = nums[right];
                left++;
            }
            right++;
        }
        for (int i = 0; i < zero; i++) {
            nums[left+i] = 0;
        }
        System.out.println(Arrays.toString(nums));
    }
    public int[] sum(int[] nums, int target){
        Map<Integer,Integer> map = new HashMap<>();
        for (int i = 0; i < nums.length; i++) {
            if (map.containsKey(target - nums[i])){
                return new int[]{map.get(target - nums[i]), i};
            }else
                map.put(nums[i],i);
        }
        return new int[2];
    }
}